"use strict";

import Mirror from '../objs/mirror.js';

const w = window.screen.width;
const h = window.screen.height;

function randMirrors(n) {
  let ms = [];
  for (let i=0; i<n; i++)
    ms.push(new Mirror(Math.random()*w,
                       54+Math.random()*(h-54),
                       Math.PI*(2*Math.random()-1)));
  return ms;
}

function randSource(src, dr) {
  let r = 4*Math.random();
  let i = Math.floor(r);
  r -= i+0.5;
  r = 4*r*r*r+0.5;
  switch (i) {
    case 0:
      src[0] = w*r;
      src[1] = 0;
      dr[0] = 0;
      dr[1] = 1;
      break;
    case 1:
      src[0] = 0;
      src[1] = 54+(h-54)*r;
      dr[0] = 1;
      dr[1] = 0;
      break;
    case 2:
      src[0] = w*r;
      src[1] = h;
      dr[0] = 0;
      dr[1] = -1;
      break;
    case 3:
      src[0] = w;
      src[1] = 54+(h-54)*r;
      dr[0] = -1;
      dr[1] = 0;
      break;
  }
}

function randPoint(t) {
  t[0] = Math.random()*w;
  t[1] = h*Math.random();
}

const WR = 32;

function randWall(t) {
  let x = Math.random()*w, y = Math.random()*h;
  let rad = (Math.random()*2-1)*Math.PI;
  let wx = WR*Math.cos(rad), wy = WR*Math.sin(rad);
  t.push(x+wx);
  t.push(y+wy);
  t.push(x-wx);
  t.push(y-wy);
}

export {randMirrors, randSource, randPoint, randWall};